home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / nihcl-30.lha / nihcl-3.0 / lib / IdentDict.c < prev    next >
C/C++ Source or Header  |  1990-05-19  |  3KB  |  115 lines

  1. /* IdentDict.c -- implementation of Identifier Dictionary
  2.  
  3.     THIS SOFTWARE FITS THE DESCRIPTION IN THE U.S. COPYRIGHT ACT OF A
  4.     "UNITED STATES GOVERNMENT WORK".  IT WAS WRITTEN AS A PART OF THE
  5.     AUTHOR'S OFFICIAL DUTIES AS A GOVERNMENT EMPLOYEE.  THIS MEANS IT
  6.     CANNOT BE COPYRIGHTED.  THIS SOFTWARE IS FREELY AVAILABLE TO THE
  7.     PUBLIC FOR USE WITHOUT A COPYRIGHT NOTICE, AND THERE ARE NO
  8.     RESTRICTIONS ON ITS USE, NOW OR SUBSEQUENTLY.
  9.  
  10. Author:
  11.     K. E. Gorlen
  12.     Bg. 12A, Rm. 2033
  13.     Computer Systems Laboratory
  14.     Division of Computer Research and Technology
  15.     National Institutes of Health
  16.     Bethesda, Maryland 20892
  17.     Phone: (301) 496-1111
  18.     uucp: uunet!nih-csl!kgorlen
  19.     Internet: kgorlen@alw.nih.gov
  20.     October, 1985
  21.  
  22. Function:
  23.     
  24. An IdentDict is like a Dictionary, except keys are compared using
  25. isSame() rather than isEqual().
  26.  
  27. $Log:    IdentDict.c,v $
  28.  * Revision 3.0  90/05/20  00:19:48  kgorlen
  29.  * Release for 1st edition.
  30.  * 
  31. */
  32.  
  33. #include "IdentDict.h"
  34. #include "LookupKey.h"
  35.  
  36. #define    THIS    IdentDict
  37. #define    BASE    Dictionary
  38. #define BASE_CLASSES BASE::desc()
  39. #define MEMBER_CLASSES
  40. #define VIRTUAL_BASE_CLASSES
  41.  
  42. DEFINE_CLASS(IdentDict,0,"$Header: /afs/alw.nih.gov/unix/sun4_40c/usr/local/src/nihcl-3.0/share/lib/RCS/IdentDict.c,v 3.0 90/05/20 00:19:48 kgorlen Rel $",NULL,NULL);
  43.  
  44. IdentDict::IdentDict(unsigned size) : BASE(size) {}
  45.  
  46. #ifndef BUG_TOOBIG
  47. // yacc stack overflow
  48. IdentDict::IdentDict(const IdentDict& c) : BASE(c) {}
  49. #endif
  50.  
  51. void IdentDict::operator=(const IdentDict& d)
  52. {
  53.     this->Dictionary::operator=(d);
  54. }
  55.  
  56. int IdentDict::findIndexOf(const Object& ob) const
  57. /*
  58. Search this IdentDict for a LookupKey with the same key object as the
  59. argument.
  60.  
  61. Enter:
  62.     ob = pointer to LookupKey to search for
  63.  
  64. Returns:
  65.     index of object if found or of nil slot if not found
  66.     
  67. Algorithm L, Knuth Vol. 3, p. 519
  68. */
  69. {
  70.     register int i;
  71.     Object* keyob = LookupKey::castdown(ob).key();
  72.     for (i = h((int)keyob); contents[i]!=nil; i = (i-1)&mask) {
  73.         if (LookupKey::castdown(contents[i])->key()->isSame(*keyob)) return i;
  74.     }
  75.     return i;
  76. }
  77.  
  78. Object* IdentDict::atKey(const Object& key) const
  79. {
  80.     return Dictionary::atKey(LookupKey((Object&)key));
  81. }
  82.  
  83. Object* IdentDict::atKey(const Object& key, Object& newValue)
  84. {
  85.     return Dictionary::atKey(LookupKey((Object&)key), newValue);
  86. }
  87.  
  88. LookupKey* IdentDict::assocAt(const Object& key) const
  89. {
  90.     return Dictionary::assocAt(LookupKey((Object&)key));
  91. }
  92.  
  93. bool IdentDict::includesKey(const Object& key) const
  94. {
  95.     return Dictionary::includesKey(LookupKey((Object&)key));
  96. }
  97.  
  98. IdentDict::IdentDict(OIOin& strm)
  99. :
  100. #ifdef MI
  101.     Object(strm),
  102. #endif
  103.     BASE(strm)
  104. {
  105. }
  106.  
  107. IdentDict::IdentDict(OIOifd& fd)
  108. :
  109. #ifdef MI
  110.     Object(fd),
  111. #endif
  112.     BASE(fd)
  113. {
  114. }
  115.